<?php

namespace common\models\auth;

use Yii;
use common\models\BaseModels;

/**
 * This is the model class for table "user_admin_team".
 *
 * @property integer $id
 * @property integer $parent_id
 * @property string $code
 * @property string $title
 * @property string $sub_title
 * @property string $slogan
 * @property string $remark
 * @property integer $i_order
 * @property integer $is_valid
 * @property integer $created_at
 * @property integer $updated_at
 */
class UserAdminTeam extends BaseModels
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'user_admin_team';
    }

    /**
     * 获取所有级别为 Top 1的团队名称
     * dropdownList 
     */
    public function getTopTeam(){
        $condition = "is_valid=1 AND parent_id=0";
        $topArray  = []; 
        $topDept   = static::find()->where($condition)->select(['id','title'])->orderBy('id desc')->limit(20)->asArray()->all();
        foreach ($topDept as $item) {
            $topArray[$item["id"]] = $item["title"];
        }
        
        return $topArray;
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['parent_id', 'i_order', 'is_valid', 'created_at', 'updated_at'], 'integer'],
            [['code', 'title'], 'required'],
            [['code'], 'string', 'max' => 16],
            [['title', 'sub_title', 'slogan'], 'string', 'max' => 32],
            [['remark'], 'string', 'max' => 512],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id'    => Yii::t('app_table', 'ID'),
            'parent_id' => Yii::t('app_table', 'admin team parent'),
            'code'  => Yii::t('app_table', 'admin team code'),
            'title' => Yii::t('app_table', 'admin team title'),
            'sub_title' => Yii::t('app_table', 'admin team subtitle'),
            'slogan'    => Yii::t('app_table', 'admin team slogan'),
            'remark'    => Yii::t('app_table', 'remark'),
            'i_order'   => Yii::t('app_table', 'admin team order'),
            'is_valid'  => Yii::t('app_table', 'isvalid'),
            'created_at' => Yii::t('app_table', 'created_at'),
            'updated_at' => Yii::t('app_table', 'updated_at'),
        ];
    }
}
